package org.sean.framework.exception;

/**
 * Date: 2016/10/11 14:21
 *
 * @author Sean.xie
 */
@SuppressWarnings("unchecked")
public class BaseRuntimeException extends RuntimeException {
    public BaseRuntimeException() {
    }

    public BaseRuntimeException(String message) {
        super(message);
    }

    public BaseRuntimeException(String message, Throwable cause) {
        super(message, cause);
    }

    public BaseRuntimeException(Throwable cause) {
        super(cause);
    }

    public BaseRuntimeException(String message, Throwable cause, boolean enableSuppression,
                                boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public static <T extends Throwable> T findThrowable(Throwable t, Class<T> target) {
        if (t == null) {
            return null;
        }
        if (target.isAssignableFrom(t.getClass())) {
            return (T) t;
        }
        return findThrowable(t.getCause(), target);
    }

}
